/*
 * Copyright (c) 2021-2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.ffmpeg.ohos.sample.tests;

import ohos.app.Context;
import org.ffmpeg.ohos.Clip;
import org.ffmpeg.ohos.FfmpegController;
import org.ffmpeg.ohos.ShellUtils;
import org.ffmpeg.ohos.filters.DrawBoxVideoFilter;
import org.ffmpeg.ohos.sample.util.Log;
import org.ffmpeg.ohos.sample.util.ResUtil;

import java.io.File;

public class DemoDrawBoxVideoFilter {
    private final static String TAG = DemoDrawBoxVideoFilter.class.getSimpleName();

    public static boolean execute(Context ctx) {
        String input_video_file_path = ResUtil.getMediaInputFilePath(ctx, "samplevideo.mp4");
        String output_drawbox_file_path = "/storage/emulated/0/Android/data/org.ffmpeg.ohos.sample/files/Music/drawboxsamplevideo.mp4";
        String tmp_dir = "/storage/emulated/0/Android/data/org.ffmpeg.ohos.sample/files/Music/";
        File ftmp_dir = new File(tmp_dir);
        try {
            Clip clip_transpose_in = new Clip(input_video_file_path);
            Clip clip_drawbox_out = new Clip(output_drawbox_file_path);
            clip_drawbox_out.videoFilter = new DrawBoxVideoFilter(0, 0, 100, 100, 100, "#0000FF", ftmp_dir).getFilterString();
            new FfmpegController(ctx, new File("/tmp")).processVideo(clip_transpose_in,
                    clip_drawbox_out, false, new ShellUtils.ShellCallback() {
                        @Override
                        public void shellOut(String shellLine) {}

                        @Override
                        public void processComplete(int exitValue) {
                            if (exitValue != 0)
                                Log.e(TAG, " processComplete operation fail");
                        }
                    });
            return true;
        } catch (Exception e) {
            Log.e(TAG, " Got Exception=" + e.getMessage());
            return false;
        }
    }
}

